﻿using UnityEngine;

public class SnakeManager {
	// === Public =====================================================================================================
	public static SnakeManager CreateInstance() {
		var instance = new SnakeManager();
		return instance;
	}

	public void Create() {
		CreateParent();
		Managers.Body.CreateBody(_parent, FieldBodyType.Head);
		IncreaseTail();
	}

	public void Destroy() {
		Managers.Body.DestroyBodies();
		Object.Destroy(_parent);
	}

	public void IncreaseTail() {
		Managers.Body.CreateBody(_parent, FieldBodyType.Tail);
	}

	public void ReduceTail(FieldBody body) {
		if (GameData.GetInstance.Bodies.Count > Constants.MIN_BODY_LENGTH) {
			Managers.Body.DestroyBody(body);
		}
	}

	// === Private ====================================================================================================
	private GameObject _parent;

	private void CreateParent() {
		_parent = new GameObject("Snake");
	}
}
